package com.wj.szcrm.service.impl;

import com.wj.szcrm.mapper.CourseOrderMapper;
import com.wj.szcrm.model.CourseOrder;
import com.wj.szcrm.model.MonthIncome;
import com.wj.szcrm.model.PageResult;
import com.wj.szcrm.service.ICourseOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author: WangJin
 * @description
 * @date: 2021/9/15 16:24
 */
@Service
public class CourseOrderServiceImpl implements ICourseOrderService {
    @Autowired
    CourseOrderMapper orderMapper;

    @Override
    public PageResult<CourseOrder> findPageResult(CourseOrder condition, int page, int pageSize) {

        PageResult<CourseOrder> result = new PageResult<CourseOrder>();
            result.setCode(0);

        Map<String, Object> params = new HashMap<String,Object>();
        params.put("condition",condition);
        params.put("start",(page-1)*pageSize);
        params.put("pageSize",pageSize);
        int totalCount = orderMapper.findCountByMap(params);
            result.setCount(totalCount);
            List<CourseOrder> list = orderMapper.findListByMap(params);
            result.setData(list);
            return result;
    }

    @Override
    public void save(CourseOrder order) {
        orderMapper.insert(order);
    }

    @Override
    public CourseOrder findByOrderId(String order_id) {
        return orderMapper.findByOrderId(order_id);
    }

    @Override
    public void deleteById(String order_id) {
        orderMapper.deleteById(order_id);
    }

    @Override
    public void update(CourseOrder order) {
        orderMapper.update(order);
    }

    @Override
    public List<MonthIncome> getMonthIncomes() {
        return orderMapper.getMonthIncomes();
    }
}
